// MX610Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "MX610Console.h"
#include "..\MXLights.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{


			if (argc<2)
			{

				cout << "* MX610 Lamplighter Console * (c) 2005 Dmitry Lysenko" << endl;
				
				cout << "Uses: MX610LLC.EXE [Control code]" << endl;
				cout << "Control codes:" << endl;
				cout << " 0:MAIL_OFF" << endl;
				cout << " 1:MAIL_ON" << endl;
				cout << " 2:MAIL_PULSE" << endl;
				cout << " 3:MAIL_FLASH" << endl;
				cout << " 4:MAIL_INSTANTON" << endl;
				cout << " 5:MAIL_INSTANTOFF" << endl;
				cout << " 6:MESSENGER_OFF" << endl;
				cout << " 7:MESSENGER_ON" << endl;
				cout << " 8:MESSENGER_PULSE" << endl;
				cout << " 9:MESSENGER_FLASH" << endl;
				cout << "10:MESSENGER_INSTANTON" << endl;
				cout << "11:MESSENGER_INSTANTOFF" << endl;

				return 0;
			}

			


			CMX610Lights MX610;

			CString S=argv[1];

			if (!MX610.Open()) 
			{	cerr << _T("Fatal Error: No MX610 mouse found") << endl;
				return -1;
			}

			S.TrimLeft();
			S.TrimRight();
			
			if (S.GetLength()!=0)
			{
				int N=atoi(S);
				MX610.TurnOffLedsOnExit(false);
				MX610.Control(N);

				return 1;
			}


	}

	return nRetCode;
}


